import http from './http'

export interface Product {
  ID?: number
  name: string
  price: number
  stock: number
  code?: string
  unit?: string
  category?: string
  description?: string
  min_stock?: number
}

export interface ProductSearchParams {
  name?: string
  category?: string
  min_price?: number
  max_price?: number
}

export const productsApi = {
  // 获取产品列表
  getList: () => http.get<Product[]>('/products'),

  // 获取单个产品
  getDetail: (id: number) => http.get<Product>(`/products/${id}`),

  // 创建产品
  create: (product: Omit<Product, 'ID'>) => http.post('/products', product),

  // 更新产品
  update: (id: number, product: Partial<Product>) => http.put(`/products/${id}`, product),

  // 删除产品
  delete: (id: number) => http.delete(`/products/${id}`),

  // 更新库存
  updateStock: (id: number, stock: number) => http.post(`/products/${id}/stock`, { stock }),

  // 搜索产品
  search: (params: ProductSearchParams) => http.get('/products/search', { params })
} 